package com.weige.conver.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.StringUtils;

import java.io.*;
import java.util.HashMap;

@Component
public class FileUtils {

    public static HashMap getBaseMap() throws IOException {
        File file = new File(filePath());
        BufferedReader br = new BufferedReader(new FileReader(file));
        String data = null;
        HashMap baseMap = new HashMap();
        while ((data = br.readLine()) != null) {
            baseMap.put(StringUtils.substringBefore(data, "="), StringUtils.substringAfter(data, "="));
        }
        br.close();
        return baseMap;
    }


    public static String filePath() throws IOException {
        File f = new File("");
        String courseFile = f.getCanonicalPath() + "/conf";
        String path = courseFile + "/site.txt";
        return path;
    }

    public static String jsonFilePath(String fileName) throws IOException {
        File f = new File("");
        String courseFile = f.getCanonicalPath() + "/conf";
        String path = courseFile + "/"+fileName;
        return path;
    }
}
